package com.example.keli.base.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.keli.R;
import com.example.keli.base.BaseDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * description: 性别选择
 * author: Allen
 * date: 19-6-11 下午12:26
 */
public class SexSelectDialog extends BaseDialog {

    private static final String TAG = "SexSelectDialog";
    @BindView(R.id.girl_iv)
    ImageView girlIv;
    @BindView(R.id.girl_tv)
    TextView girlTv;
    @BindView(R.id.boy_iv)
    ImageView boyIv;
    @BindView(R.id.boy_tv)
    TextView boyTv;
    @BindView(R.id.both_iv)
    ImageView bothIv;
    @BindView(R.id.both_tv)
    TextView bothTv;
    @BindView(R.id.confirm)
    TextView confirm;
    @BindView(R.id.ll_basic)
    LinearLayout llBasic;
    //image顺序，0女，1男，2全部
    int index = 0;

    List<ImageView> imageViews = new ArrayList<>();
    SexListener onSexListener;

    public SexSelectDialog(@NonNull Context context, int index,SexListener onSexListener) {
        super(context);
        this.index = index;
        this.onSexListener = onSexListener;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.dialog_select_sex;
    }

    @Override
    protected void onInitView() {
        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        imageViews.add(girlIv);
        imageViews.add(boyIv);
        imageViews.add(bothIv);
    }

    @Override
    protected void onInitData() {
        imageViews.get(index).setSelected(true);
    }

    @OnClick({R.id.girl_iv, R.id.boy_iv, R.id.both_iv, R.id.confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.girl_iv:
                imageViews.get(index).setSelected(false);
                index = 0;
                imageViews.get(index).setSelected(true);
                break;
            case R.id.boy_iv:
                imageViews.get(index).setSelected(false);
                index = 1;
                imageViews.get(index).setSelected(true);
                break;
            case R.id.both_iv:
                imageViews.get(index).setSelected(false);
                index = 2;
                imageViews.get(index).setSelected(true);
                break;
            case R.id.confirm:
                onSexListener.callSex(index);
                dismiss();
                break;
        }
    }

    public interface SexListener{
        void callSex(int sex);
    }
}
